package com.dianping.cat.consumer.cross.model.transform;

import com.dianping.cat.consumer.cross.model.IEntity;
import com.dianping.cat.consumer.cross.model.IVisitor;
import com.dianping.cat.consumer.cross.model.entity.CrossReport;
import com.dianping.cat.consumer.cross.model.entity.Local;
import com.dianping.cat.consumer.cross.model.entity.Name;
import com.dianping.cat.consumer.cross.model.entity.Remote;
import com.dianping.cat.consumer.cross.model.entity.Type;
import java.util.Stack;

public class DefaultMerger
  implements IVisitor
{
/*  15 */   private Stack<Object> m_objs = new Stack();

  private CrossReport m_crossReport;


  public DefaultMerger() {}

  public DefaultMerger(CrossReport crossReport) {
/*  23 */     this.m_crossReport = crossReport;
    this.m_objs.push(crossReport);
  }


/*  28 */   public CrossReport getCrossReport() { return this.m_crossReport; }



  protected Stack<Object> getObjects() { return this.m_objs; }


  public <T> void merge(IEntity<T> to, IEntity<T> from) {
    this.m_objs.push(to);
/*  37 */     from.accept(this);
/*  38 */     this.m_objs.pop();
  }

  protected void mergeCrossReport(CrossReport to, CrossReport from) {
/*  42 */     to.mergeAttributes(from);
/*  43 */     to.getDomainNames().addAll(from.getDomainNames());
/*  44 */     to.getIps().addAll(from.getIps());
  }


/*  48 */   protected void mergeLocal(Local to, Local from) { to.mergeAttributes(from); }



/*  52 */   protected void mergeName(Name to, Name from) { to.mergeAttributes(from); }



/*  56 */   protected void mergeRemote(Remote to, Remote from) { to.mergeAttributes(from); }



/*  60 */   protected void mergeType(Type to, Type from) { to.mergeAttributes(from); }



  public void visitCrossReport(CrossReport from) {
/*  65 */     CrossReport to = (CrossReport)this.m_objs.peek();

/*  67 */     mergeCrossReport(to, from);
/*  68 */     visitCrossReportChildren(to, from);
  }

  protected void visitCrossReportChildren(CrossReport to, CrossReport from) {
/*  72 */     for (Local source : from.getLocals().values()) {
/*  73 */       Local target = to.findLocal(source.getId());

/*  75 */       if (target == null) {
/*  76 */         target = new Local(source.getId());
/*  77 */         to.addLocal(target);
      }

/*  80 */       this.m_objs.push(target);
/*  81 */       source.accept(this);
/*  82 */       this.m_objs.pop();
    }
  }


  public void visitLocal(Local from) {
/*  88 */     Local to = (Local)this.m_objs.peek();

/*  90 */     mergeLocal(to, from);
/*  91 */     visitLocalChildren(to, from);
  }

  protected void visitLocalChildren(Local to, Local from) {
/*  95 */     for (Remote source : from.getRemotes().values()) {
/*  96 */       Remote target = to.findRemote(source.getId());

/*  98 */       if (target == null) {
/*  99 */         target = new Remote(source.getId());
/* 100 */         to.addRemote(target);
      }

/* 103 */       this.m_objs.push(target);
/* 104 */       source.accept(this);
/* 105 */       this.m_objs.pop();
    }
  }


  public void visitName(Name from) {
/* 111 */     Name to = (Name)this.m_objs.peek();

/* 113 */     mergeName(to, from);
/* 114 */     visitNameChildren(to, from);
  }


  protected void visitNameChildren(Name to, Name from) {}


  public void visitRemote(Remote from) {
/* 122 */     Remote to = (Remote)this.m_objs.peek();

/* 124 */     mergeRemote(to, from);
/* 125 */     visitRemoteChildren(to, from);
  }

  protected void visitRemoteChildren(Remote to, Remote from) {
/* 129 */     if (from.getType() != null) {
/* 130 */       Type target = to.getType();

/* 132 */       if (target == null) {
/* 133 */         target = new Type();
/* 134 */         to.setType(target);
      }

/* 137 */       this.m_objs.push(target);
/* 138 */       from.getType().accept(this);
/* 139 */       this.m_objs.pop();
    }
  }


  public void visitType(Type from) {
/* 145 */     Type to = (Type)this.m_objs.peek();

/* 147 */     mergeType(to, from);
/* 148 */     visitTypeChildren(to, from);
  }

  protected void visitTypeChildren(Type to, Type from) {
/* 152 */     for (Name source : from.getNames().values()) {
/* 153 */       Name target = to.findName(source.getId());

/* 155 */       if (target == null) {
/* 156 */         target = new Name(source.getId());
/* 157 */         to.addName(target);
      }

/* 160 */       this.m_objs.push(target);
/* 161 */       source.accept(this);
/* 162 */       this.m_objs.pop();
    }
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/lib/cat-consumer-3.0.0.jar!/com/dianping/cat/consumer/cross/model/transform/DefaultMerger.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */